package com.dspsemi.wodi.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dspsemi.wodi.R;
import com.dspsemi.wodi.entity.Room;

public class RoomListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<Room> list;
	private Context c;

	public RoomListAdapter(Context context, ArrayList<Room> it) {
		mInflater = LayoutInflater.from(context);
		c = context;
		list = it;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_room_listview, null);
			holder = new ViewHolder();

			holder.number = (TextView) convertView.findViewById(R.id.number);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.people = (TextView) convertView.findViewById(R.id.people);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.number.setText(list.get(position).getNumber());
		holder.name.setText(list.get(position).getName());
		holder.people.setText(list.get(position).getPeople());

		return convertView;
	}

	private class ViewHolder {
		public TextView number;
		public TextView name;
		public TextView people;
	}

}
